package com.yunze.apiCommon.upstreamAPI.ZY_ZhiShu.Inquire;



import com.yunze.apiCommon.upstreamAPI.ZY_ZhiShu.ZY_ZhiShu_Api;
import com.yunze.apiCommon.upstreamAPI.ZY_ZhiShu.change.serviceAccept_ZY_ZhiShu;
import com.yunze.apiCommon.utils.HttpUtil;
import com.yunze.apiCommon.utils.UrlUtil;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * 查询类接口
 */
public class Query_ZT_ZhiShu extends ZY_ZhiShu_Api {

    public static void main(String[] args) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("cd_username", "lianhui");
        map.put("cd_pwd","e7538e58e20e25ca57d43a9aea872991");
        map.put("cd_key", "lianhui");

        Query_ZT_ZhiShu Qy = new Query_ZT_ZhiShu(map);
        serviceAccept_ZY_ZhiShu sT = new serviceAccept_ZY_ZhiShu(map);

       /* System.out.println();
        for (int i = 0; i <9000 ; i++) {
            String day = ""+((int)(1+Math.random()*(31-1+1)));
            if(day.length()==1){
                day = "0"+day;
            }
            System.out.println("2021-08-"+day);
        }*/
         System.out.println(sT.buyPackage("8986112027708746874","dqdx-251b1ef2-9c11f845","month"));



        for (int i = 0; i <1 ; i++) {
            //System.out.println(Qy.queryFlow("8986112027708747124"));
            ////System.out.println(Qy.queryCardStatus("8986062004001260203"));
            ////System.out.println(Qy.queryAPN("89860620070018212864"));
            ////System.out.println(sT.changeNetwork("89860620040012613177","21010498"));

            ////System.out.println(sT.changeCardStatus("89860620070018173801","2")); // 2已激活-3已停用
           /*
            //System.out.println(Qy.queryFlowHis("89860620040012613177","202101"));
            //System.out.println(Qy.queryRealNameStatus("89860620040012613177"));
            //System.out.println(Qy.queryNetWork("89860620040012613177"));//404 暂未用到

            //System.out.println(sT.changeNetwork("89860620040012613177","21010498"));
            //System.out.println(Qy.queryNetWork("89860620040012613177"));//404 暂未用到


            //System.out.println(Qy.queryAPN("89860620040012613177"));//404 暂未用到*/

            ////System.out.println(sT.changeCardStatus("89860620040012613177","3")); // 2已激活-3已停用
/*
            //System.out.println(Qy.queryBatchUsedFlow("89860620040012799323"));
            //System.out.println(Qy.queryFlow("89860620040012799323"));*/


        }
        //serviceAccept_LT Change = new serviceAccept_LT(map);
        // ////System.out.println(Qy.queryFlowHis("89860620210011019177","202011"));

        //////System.out.println(Qy.queryRealNameStatus("8986062022006084028"));

        //////System.out.println(Qy.queryCardStatus("89860620220053321332"));
/*
/*      String iccid = "89860620210011019177";
        ////System.out.println(iccid);
        iccid = iccid.length()>19?iccid.substring(0,19):iccid;
        ////System.out.println(iccid);*/


        // ////System.out.println(Qy.queryRealNameStatus("8986062021001111760"));

        //////System.out.println(Qy.queryRealNameStatus("8986062021001101917"));

        // ////System.out.println(serviceAccefpt_LT.changeCardStatus("89860620210011062912","3"));


        //最新实名查询


        /*String timestamp = VeDate.getStringDate();
        String nonce = My_RandomUtil.getHow_Many_Digits_Random_Number(7)+"";
        String account = "sdxfwy004982cus";
        //String account = "sdxfwy0004982cus";
        //String appkey = "okhd#98sds";
        String appkey = "okhdg#98sds";

                //"                                                            account=12345&timestamp=2019-08-27 17:19:27.95&nonce=7&appkey=888888";
        String sign = MD5Util.MD5Encode(MessageFormat.format("account={0}&timestamp={1}&nonce={2}&appkey={3}", account, timestamp, nonce,appkey));


        // 拼接请求参数
        JSONObject params = new JSONObject();
        params.put("iccid", "8986112025403598277");

        //请求头部参数
        Map<String,String> headers = new HashMap<String, String>();
        headers.put("account", account);
        headers.put("timestamp", timestamp);
        headers.put("nonce", nonce);
        headers.put("sign", sign);

        String api_url = "https://smz.cuiot.cn/smz/newapi/query/queryByIccid";
        //String api_url = "https://smztest.cuiot.cn/smz/newapi/query/queryByIccid";
        String Jstr = params.toJSONString();
        ////System.out.println(Jstr);
        String res = HttpUtil.post(api_url, Jstr, headers);
        ////System.out.println(res);*/
    }


    public Query_ZT_ZhiShu(Map<String, Object> init_map) {
        super(init_map);
    }


    /**
     * 获取单个卡的流量
     * @param iccid
     * @param
     * @return
     */
    public static String queryFlow(String iccid) {

        String Rstr = null;
        try {
            Map<String, Object> params = new HashMap<>();
            params.put("account",account);
            params.put("password",password);
            params.put("version",version);
            params.put("timeStamp",System.currentTimeMillis()+"");
            params.put("iccid",iccid);
            params.put("agentId",account);

            //////System.out.println(params);
            String sign = getSign(params, password);
            params.put("sign",sign);
            String url = server_Ip + "/queryFlow";
            String reqUrl = UrlUtil.getUrl(url, params);
            System.out.println(reqUrl);
             Rstr = HttpUtil.get(reqUrl);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return Rstr;
    }




    /**
     * 获取单个卡的流量
     * @param iccid
     * @param
     * @return
     */
    public static String queryBatchUsedFlow(String iccid) {

        String Rstr = null;
        try {
            Map<String, Object> params = new HashMap<>();
            params.put("account",account);
            params.put("password",password);
            params.put("version",version);
            params.put("timeStamp",System.currentTimeMillis()+"");

            //////System.out.println(params);
            String sign = getSign(params, accessKey);
            params.put("sign",sign);
            params.put("iccids",iccid);
            String url = server_Ip + "/queryBatchUsedFlow";
            String reqUrl = UrlUtil.getUrl(url, params);
            //System.out.println(params.toString());
            //Rstr = HttpUtil.get(reqUrl);
            Rstr =  HttpUtil.post(reqUrl,params.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Rstr;
    }



    /**
     * 历史流量查询
     * @param iccid
     * @param time
     * @return
     */
    public static String queryFlowHis(String iccid, String time) {
        String Rstr = null;
        try {
            Map<String, Object> params = new HashMap<>();
            params.put("account",account);
            params.put("password",password);
            params.put("version",version);
            params.put("timeStamp",System.currentTimeMillis()+"");
            params.put("iccid",iccid);
            String sign = getSign(params, accessKey);
            params.put("sign",sign);
            String url = server_Ip + "/queryFlowHis";
            String reqUrl = UrlUtil.getUrl(url, params);
            ////System.out.println(reqUrl);
            Rstr = HttpUtil.get(reqUrl);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return Rstr;
    }


    /**
     * 创建人      创建时间  2019年8月5日下午2:28:31
     * 项目描述
     * SIM卡状态:
     * "0": 可测试,
     * "1": 可激活,
     * "2": 已激活,
     * "3": 已停用,
     * "4": 已失效,
     * "5"": 已清除,
     * "6": 已更换,
     * "7": 库存,
     * "8": 开始
     *
     * @throws IOException
     */
    @SuppressWarnings("unchecked")
    public static String queryCardStatus(String iccid) {
        String Rstr = null;
        try {
            Map<String, Object> params = new HashMap<>();
            params.put("account",account);
            params.put("password",password);
            params.put("version",version);
            params.put("timeStamp",System.currentTimeMillis()+"");
            params.put("iccid",iccid);
            String sign = getSign(params, accessKey);
            params.put("sign",sign);
            String url = server_Ip + "/queryCardStatus";
            String reqUrl = UrlUtil.getUrl(url, params);
            //System.out.println(reqUrl);
            Rstr = HttpUtil.get(reqUrl);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return Rstr;
    }


    /**
     * 创建人     创建时间  2019年11月4日下午2:35:57
     * 项目描述    	查询通讯计划-限速   单卡接口
     * 0-  恢复正常
     * 1-  上下行限速1Mbps
     * 2-  上下行限速2Mbps
     * 4-  上下行限速4Mbps
     * 8-  上下行限速8Mbps
     * -1-  上下行限速0.5Mbps
     * -2-  上下行限速256Kbps
     *
     * @throws IOException
     */
    public static String queryNetWork(String iccid) {
        String Rstr = null;
        try {
            Map<String, Object> params = new HashMap<>();
            params.put("account",account);
            params.put("password",password);
            params.put("version",version);
            params.put("timeStamp",System.currentTimeMillis()+"");
            params.put("iccid",iccid);
            String sign = getSign(params, accessKey);
            params.put("sign",sign);
            String url = server_Ip + "/queryNetwork";
            String reqUrl = UrlUtil.getUrl(url, params);
            ////System.out.println(reqUrl);
            Rstr = HttpUtil.get(reqUrl);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return Rstr;
    }




    /**
     * 创建人     创建时间  2019年8月13日下午3:41:47
     * 项目描述	查询是否需要实名认证
     * 返回 true :已实名   不需要再实名
     * fasle   :未实名   需要实名认证
     *
     * @throws IOException
     */
    public static String queryRealNameStatus(String iccid) {
        String Rstr = null;
        try {
            Map<String, Object> params = new HashMap<>();
            params.put("account",account);
            params.put("password",password);
            params.put("version",version);
            params.put("timeStamp",System.currentTimeMillis()+"");
            params.put("iccid",iccid);
            String sign = getSign(params, accessKey);
            params.put("sign",sign);
            String url = server_Ip + "/queryAuth";
            String reqUrl = UrlUtil.getUrl(url, params);
            //System.out.println(reqUrl);
            Rstr = HttpUtil.get(reqUrl);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return Rstr;
    }





    /**
     * 创建人     创建时间  2019年11月4日下午2:35:57
     * 项目描述    	查询APN设置信息
     *
     * @throws IOException
     */
    public static String queryAPN(String iccid) {
        String Rstr = null;
        try {
            Map<String, Object> params = new HashMap<>();
            params.put("account",account);
            params.put("password",password);
            params.put("version",version);
            params.put("timeStamp",System.currentTimeMillis()+"");
            params.put("iccid",iccid);
            String sign = getSign(params, accessKey);
            params.put("sign",sign);
            String url = server_Ip + "/queryAPN";
            String reqUrl = UrlUtil.getUrl(url, params);
            ////System.out.println(reqUrl);
            Rstr = HttpUtil.get(reqUrl);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return Rstr;
    }





}
